#ifndef AVALON_TCPSOCKETCONNECTION_HPP
#define AVALON_TCPSOCKETCONNECTION_HPP
#include "Avalon/IO/ClientConnection.hpp"
#include "Avalon/Network/Network.hpp"

namespace Avalon {
namespace Network {

  /*! \class TcpSocketConnection
   *  \brief Implements the ClientConnection using a TCP socket.
   */
  class TcpSocketConnection : public IO::ClientConnection {
    public:
      virtual ~TcpSocketConnection();

      virtual void Open();

      virtual bool IsOpen() const;

      virtual void Close();

      virtual void SetClosedSlot(const ClosedSlot& slot, Out<bool> isOpen);

    private:
      friend class TcpServerSocket;
      friend class TcpClientSocketChannel;
      mutable boost::mutex m_mutex;
      bool m_isOpen;
      IpAddress m_address;
      boost::shared_ptr<Detail::SocketType> m_socket;
      boost::weak_ptr<TcpSocketReader> m_reader;
      boost::weak_ptr<TcpSocketWriter> m_writer;
      boost::shared_ptr<ClosedSlot> m_closedSlot;

      TcpSocketConnection(bool isOpen, const IpAddress& address,
        const boost::shared_ptr<Detail::SocketType>& socket,
        const boost::shared_ptr<TcpSocketReader>& reader,
        const boost::shared_ptr<TcpSocketWriter>& writer);
  };
}
}

#endif // AVALON_TCPSOCKETCONNECTION_HPP
